package com.example.smartpark.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.smartpark.common.Result;
import com.example.smartpark.dto.AnnouncementCategoryDTO;
import com.example.smartpark.service.AnnouncementCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公告分类Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/announcement-categories")
public class AnnouncementCategoryController {

    @Autowired
    private AnnouncementCategoryService categoryService;

    /**
     * 获取所有公告分类
     *
     * @return 分类列表
     */
    @GetMapping
    public Result<List<AnnouncementCategoryDTO>> getAllCategories() {
        log.info("获取所有公告分类");
        List<AnnouncementCategoryDTO> categories = categoryService.getAllCategories();
        return Result.success(categories);
    }

    /**
     * 分页获取公告分类
     *
     * @param page 页码
     * @param size 每页大小
     * @return 分页结果
     */
    @GetMapping("/page")
    public Result<IPage<AnnouncementCategoryDTO>> getCategoryPage(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        log.info("分页获取公告分类: page={}, size={}", page, size);
        IPage<AnnouncementCategoryDTO> categoryPage = categoryService.getCategoryPage(page, size);
        return Result.success(categoryPage);
    }

    /**
     * 获取公告分类详情
     *
     * @param id 分类ID
     * @return 分类详情
     */
    @GetMapping("/{id}")
    public Result<AnnouncementCategoryDTO> getCategoryDetail(@PathVariable Integer id) {
        log.info("获取公告分类详情: {}", id);
        AnnouncementCategoryDTO category = categoryService.getCategoryById(id);
        return Result.success(category);
    }
} 